<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!DOCTYPE html>
<html>

<head>
    <link href="${ctx}/static/inspinia/js/plugins/iCheck/dcwj.css" rel="stylesheet">
    <style type="text/css">
        th,tr{
            text-align:center;
            vertical-align:middle!important;
        }
        .text-style{
            text-align:center;
            vertical-align:middle!important;
        }
        table{
            color: #000;
        }
        .colspan-title{
            color: #70c7b1;
            text-align: left;
        }
    </style>
</head>
<body>
<span class="navbar-right  m-r m-t-8"><a href="${ctx}/admin/ehm/question/list" class="btn-primary btn-add "> <i class='fa fa-plus-square-o'></i>返 回</a></span>
    <div id="wrapper">
        <div class="gray-bg p-sm">

            <div class="row">
                <div class="col-lg-12">
                        <span class="navbar-right  m-r m-t-8"><input type="button" onclick="downexcel()" value="导出"/> </span>
                        <div class="tabs-container">
                        <ul class="nav nav-tabs">
                            <li class=""><a  href="${ctx}/admin/ehm/question/tz/edit">问卷分析</a></li>
                            <li class="active"><a  href="javascript:void(0)">列表分析</a></li>
                        </ul>
                    </div>
                   <div class="dcwj white-bg">
                       <div class="dcwj-content p-md">
                           <c:if test="${!sys_flag}">
                               <form role="form" class="form-inline" id="queryform">
                                   <label for="companyId">
                                       <select id="companyId" name="companyId"  class="form-control form-filter" form="queryform" style="width:100%">
                                           <option value="">请选择企业</option>
                                           <c:forEach var="items" items="${company}">
                                               <option value="${items.id}" <c:if test="${items.id == companyId}">selected="true"</c:if>>${items.title}</option>
                                           </c:forEach>
                                       </select></label>
                                   <button class="btn btn-primary" type="button" onclick="query()"> 查询</button>
                               </form>
                           </c:if>
                               <div class="table-responsive">
                                   <table class="table table-bordered" id="showTbody">
                                       <thead>
                                       <tr>
                                           <th class="col-md-4">调查问卷</th>
                                           <th class="col-md-1">调查人数</th>
                                           <th class="col-md-3">可选项</th>
                                           <th class="col-md-2">数量</th>
                                           <th class="col-md-2">占比(%)</th>
                                       </tr>
                                       </thead>
                                       <tbody >

                                       </tbody>
                                   </table>
                               </div>
                       </div>
                   </div>
                </div>
            </div>
        </div>
    </div>
    <script type="text/javascript">
        var no;
        $(document).ready(function() {
            no = ${count};
            var show = JSON.parse('${data}');
            var content = "";
            for (var n = 0 ; n < show.length ; n++) {
                if(n == 0){
                    content += "<tr><td colspan='5' class='colspan-title'>&bull;&nbsp;基本信息</td></tr>"
                }
                if(n == 2){
                    content += "<tr><td colspan='5' class='colspan-title'>&bull;&nbsp;个人现状 (可多选)</td></tr>"
                }
                if(n == 4){
                    content += "<tr><td colspan='5' class='colspan-title'>&bull;&nbsp;健康企业创建意见和建议</td></tr>"
                }
                var itemData = show[n].items;
                var itemLenth = itemData.length;
                content+="<tr>"+
                    "<td rowspan='"+itemLenth+"' class='text-style'>"+show[n].title+"</td>"+
                    "<td rowspan='"+itemLenth+"' class='text-style'>"+no+"</td>";

                for (var j = 0 ; j<itemData.length ; j++) {
                    if(j!=0){
                        content+="<tr>";
                    }
                    content+="<td>"+itemData[j].title+"</td>"+
                        "<td>"+itemData[j].no+"</td>"+
                        "<td>"+itemData[j].percentile+"%</td>"+
                        " </tr>";
                }

            }
            $("#showTbody tbody").append(content);
        });

        function query() {
            var companyId = $("#companyId").val();
            if(companyId!=null && companyId!=undefined && companyId!=''){
                location.href='${ctx}/admin/ehm/question/tz/lb/edit?companyId='+companyId;
            }
        }

        function downexcel(){
            var com = $("#companyId").val();
            if(com == undefined || com == null || com==''){
                com = 0;
            }
            if(no == 0){
                parent.layer.msg("无统计数据，无法导出");
                return;
            }

            $.ajax({
                method: "POST",
                url: "${ctx}/admin/ehm/question/downPDF",
                data: {companyId : com},
                dataType: "json",
                async: false,
                success: function(response) {
                    console.log(0)
                    console.log(response)
                    if (response.code == 0) {
                        console.log(1)
                        console.log(response.path)
//                        location.href=response.path;
                        window.open(response.path);
                    }else{
                        console.log(2)
                        parent.layer.msg(response.msg);
                    }
                }
            });
            <%--location.href='${ctx}/admin/ehm/question/downWord?companyId='+com;--%>
        }
    </script>
</body>
</html>
